﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ElGee.Google.Charts;
using System.Web.Script.Serialization;
using System.Text;

namespace WebApp.AreaChartSample
{
    /// <summary>
    /// Summary description for DataSource
    /// </summary>
    public class DataSource : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            // No Cache, because need fresh values !
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            // Set the content type and encoding for JSON
            context.Response.ContentType = "application/json";
            context.Response.ContentEncoding = Encoding.UTF8;

            // Find the Construction of the DataSource in /Data/AreaChartData
            AreaChart lc = AreaChartData.GetOptions();

            ChartDataSource cds = AreaChartData.GetDataSource();

            // Create the object needed for All Asynchronous calls. Must be a LineChartDataSource
            AreaChartDataSource ds = new AreaChartDataSource(cds, lc);

            // Returning the object in JSON Format
            context.Response.Write(new JavaScriptSerializer().Serialize(ds));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}